using UnityEngine.EventSystems;
using UnityEngine.UI;
using System;
using UnityEngine.Events;

namespace ET
{
    public class OnPSliderEndDragCallback : UnityEvent<float>
    {
    }

    public class OnPSliderBeginCallback : UnityEvent
    {
    }

    public class PSlider : Slider, IEndDragHandler, IBeginDragHandler
    {
        public OnPSliderEndDragCallback onEndDragCallback = new OnPSliderEndDragCallback();
        public OnPSliderBeginCallback onbeginDragCallback = new OnPSliderBeginCallback();


        bool draging = false;

        public void OnBeginDrag(PointerEventData eventData)
        {
            draging = true;
            onbeginDragCallback?.Invoke();
        }

        public void OnEndDrag(PointerEventData eventData)
        {
            onEndDragCallback?.Invoke(value);
            draging = false;
        }

        public void SetSliderProgress(float value, float start, float end)
        {
            if (!draging)
            {
                float v = (value - start) / (end - start);
                if (v >= 0 && v <= 1)
                {
                    SetValueWithoutNotify(v);
                }
            }
        }
    }
}